﻿@{
    ViewBag.Title = "GetBillGood";
}

@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/shared/shown.js?ver=1")" type="text/javascript"></script>
}
<style type="text/css">
    .attrb{
        font-size:12pt;
        color:#5c5c5c;
    }
</style>
<form id="form1" runat="server" method="post" style="height: 100%">
    <div class="mini-toolbar" style="padding:0px;border-top:0;border-left:0;border-right:0;">
        <table style="width:100%;">
            <tr>
                <td style="white-space:nowrap;">
                    @Html.Partial("~/Views/Modular/SearchInfo.cshtml")
                </td>
                <td style="width:100%;">
                    <span class="separator"></span>
                    <a class="mini-button" iconCls="icon-ok" onclick="onInportGoods" plain="true">开始导入</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        <div id="layout1" class="mini-layout" style="width:100%;height:100%;">
            <div title="商品分类" showProxyText="true" region="west" width="170" expanded="true" showSplitIcon="true">
                <div class="mini-fit">
                    <ul id="tree1" class="mini-tree" url=""
                        style="width:100%;height:100%;" expandOnLoad="0"
                        textField="FName" idField="FItemID" parentField="FParentID" showTreeIcon="true" resultAsTree="false">
                    </ul>
                </div>
            </div>
            <div title="待选商品" region="center" showHeader="true">
                <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
                    <table>
                        <tr>
                            <td style="width:450px;">
                                <a class="mini-button" name="selectAll" iconCls="icon-add" onclick="selectAll()">添加所选</a>                                        
                            </td>
                        </tr>
                    </table>
                </div>
                    <div class="mini-fit">
                        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="10" idField="FItemID"
                                allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true"
                                borderStyle="border:0;" url="../Goods/GetGoodsListShare" multiSelect="true"
                                allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"
                                sortMode="client" ondrawcell="DrawCell" allowResizeColumn="false"
                                onselect="selectRow" onrowdblclick="adds" pagerButtons="#buttons">
                            <div property="columns">
                                <div type="checkcolumn"></div>
                                <div type="indexcolumn" width="35" headerAlign="center">序号</div>
                                <div field="FPic" name="FPic" width="60" headeralign="center" allowsort="true" style="font-size:12pt !important;">图片</div>
                                <div field="FCode" width="100" allowSort="true" headerAlign="center">条码</div>
                                <div field="FName" width="160" allowSort="true" headerAlign="center">名称</div>
                                <div field="FSpec" width="100" allowSort="true" headerAlign="center">规格</div>
                                <div field="FUnitName" width="50" allowSort="true" headerAlign="center" align="center">单位</div>
                                <div field="FConvert" width="50" allowSort="true" headerAlign="center" align="center">内装数</div>
                                <div field="FPrice" name="FPrice" width="60" numberFormat="#,0.00" headerAlign="center" align="right">单价</div>
                                <div field="FNumber" width="90" allowSort="true" headerAlign="center">编码</div>                          
                                <div name="action" width="60" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;"></div>
                            </div>
                        </div>                    
                    </div>
            </div>
            <div title="已选商品" showProxyText="true" region="east" showHeader="true" width="400" showSplitIcon="true">
                <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
                    <table>
                        <tr>
                            <td style="width:450px;">
                                <a class="mini-button" name="removeAll" iconCls="icon-add" onclick="removeAll()">全部取消</a>       
                                <a class="mini-button" name="removes" iconCls="icon-remove" onclick="removes()">取消选中项</a>       
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="mini-fit">
                    <div id="datagrid2" class="mini-datagrid" style="width:100%;height:100%;" idField="FItemID" multiSelect="true"
                            borderStyle="border:0;" url="" allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"
                            onrowdblclick="onOk" sortMode="client" showPager="false" ondrawcell="DrawCell" onselect="selectRow"
                            editNextOnEnterKey="true"  editNextRowCell="true">
                        <div property="columns">
                            <div type="checkcolumn"></div>
                            <div type="indexcolumn" width="35" headerAlign="center">序号</div>
                            <div field="FPic" name="FPic" width="60" headeralign="center" allowsort="true" style="font-size:12pt !important;">图片</div>
                            <div field="FCode" width="100" allowSort="true" headerAlign="center">条码</div>
                            <div field="FName" width="160" allowSort="true" headerAlign="center">名称</div>
                            <div field="FSpec" width="100" allowSort="true" headerAlign="center">规格</div>
                            <div field="FUnitName" width="50" allowSort="true" headerAlign="center">单位</div>
                            <div field="FPrice" name="FPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right">单价</div>
                            <div field="FNumber" width="90" allowSort="true" headerAlign="center">编码</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <table style="width:100%;">
        <tr>
            <td width ="50px" align="right">提示：</td>
            <td style="width:100%;">
                1、选择多个商品，按添加按钮添加到已选商品列表中，然后点导入；2、该商品所在的分类，如果没有则自动添加。
            </td>
        </tr>
    </table>
    <div id="buttons">
        <span class="separator"></span><a class="mini-button" iconCls="icon-add" plain="true" id="add"></a><a class="mini-button" iconCls="icon-edit" plain="true"></a><a class="mini-button" iconCls="icon-remove" plain="true"></a><input class="mini-datepicker" />
    </div>
    <script type="text/javascript">
        mini.parse();
        var uID = parent.window.getSystemAppID();
        var grid1 = mini.get("datagrid1");
        var grid2 = mini.get("datagrid2");
        LoadListTree();
        //通用shown自动调用些方式
        function FormShown() {
            var tree = mini.get("tree1");
            tree.on("nodeselect", function (e) {
                LoadListData();
            });
        }

        //加载分类树
        function LoadListTree() {
            var tree = mini.get("tree1");
            var mAppID = parent.window.getSystemAppID();
            var json = '[{"mSystemAppID":"' + mAppID + '"}]'
            $.post('../Goods/GetGoodsClassShare', { mjson: mAppID }, function (data) {
                tree.loadList(mini.decode(data));
                tree.select(0);
            });
        }

        function setkeyPress() {
            if (event.keyCode == 13) {
                LoadListData();
            }
        }

        //加载资料
        function search() {
            LoadListData();
        }

        //加载用户列表
        function LoadListData() {
            var tree = mini.get("tree1");
            var mload = tree.getData();
            if (mload.length > 0) {
                var node = tree.getSelectedNode();
                var classid = node.FItemID;
                var json = "[{";
                json = json + "'FClassID':" + "'" + classid + "',";
                json = json + "'FNumber':" + "'" + mini.getbyName("FSearchKey").getValue() + "',";
                json = json + "'FSystemAppID':'" + parent.window.getSystemAppID() + "'}]";
                var grid = mini.get("datagrid1");
                grid.load({ datajson: json });
            }
        }

        function onInportGoods(e) {
            var grid2 = mini.get("datagrid2");
            var rCnt = grid2.getData().length;
            var json = "";
            for (var i = 0; i < rCnt; i++) {
                var rs = grid2.getRow(i);
                if (datarow > 0) json = json + ",";
                json = json + '{"FItemID":' + rs.FItemID + "}";
            }
            var mjson = "[" + json + "]";
            $.ajax({
                url: '../Goods/SaveGoodsFromShare',
                data: { mdatajson: mjson },
                type: "post",
                cache: false,
                success: function (txt) {
                    var ret = mini.decode(txt);
                    if (ret.id > 0) {
                        grid2.removeAll();
                        mini.showTips({ content: "<b>保存成功</b>", state: "success", x: "center", y: "top", timeout: 3000 });
                    }
                    else {
                        mini.alert("异常:" + ret.Status);
                    }
                },
                error: function (xhr) {
                    mini.alert("异常:" + xhr.responseText);
                }
            });
        }
        function selectAll() {
            var items = grid1.getSelecteds();
            grid1.removeRows(items);
            grid2.addRows(items);
        }

        function adds() {
            var items = grid1.getSelecteds();
            grid1.removeRows(items);
            grid2.addRows(items);
        }
        function addAll() {
            var items = grid1.getData();
            grid1.removeRows(items);
            grid2.addRows(items);
        }
        function removes() {
            var items = grid2.getSelecteds();
            grid2.removeRows(items);
            grid1.addRows(items);
        }
        function removeAll() {
            mini.confirm("确定要全部取消?", "提示", function (action) {
                if (action == "ok") {
                    var items = grid2.getData();
                    grid2.removeRows(items);
                    grid1.addRows(items);
                }
            });
        }
        function selectRow(obj) {
            //$("#FMainPic").attr('src', obj.record.FPic);
        }
        function onActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record._uid;
            var rowIndex = e.rowIndex;

            var s = '<a class="New_Button" href="javascript:addRow(\'' + uid + '\')">选择</a>';
            return s;
        }
        function addRow(row_uid) {
            var items = grid1.getRowByUID(row_uid);
            grid1.removeRow(items);
            grid2.addRow(items);
        }
        function DrawCell(e) {
            if (e.columnIndex == 2) {
                var PicUrl = e.row.FPic;
                if (PicUrl == '')
                    PicUrl = '/content/images/PImage.jpg';
                e.cellHtml = '<img src="' + PicUrl + '" width="50px" height="40px" />';
            }
        }


    </script>

</form>